<template>
  <div>
    <svg width="200" height="200">
      <polygraph :stats="stats"></polygraph>
    </svg>
    <div v-for="(stat,index) in stats" :key="stat.label+index">
      <label>{{stat.label}}</label>
      <input type="range" v-model="stat.value" min="0"
      max="100" ></input>
      <span>{{stat.value}}</span>
      <button @click="remove(stat)" class="remove">X</button>
    </div>
    <form>
      <input v-model="newlabel">
      <button @click.prevent="add">Add a Stat</button>
    </form>
    <pre class="row">{{stats}}</pre>
  </div>
</template>
<script>
import Polygraph from './SvgPolygraph.vue'
export default {
  components: {
    Polygraph
  },
  data() {
    return {
      newlabel: '',
      stats: [
        { label: 'A', value: 100 },
        { label: 'B', value: 100 },
        { label: 'C', value: 100 },
        { label: 'D', value: 100 },
        { label: 'E', value: 100 },
        { label: 'F', value: 100 }
      ]
    }
  },
  methods: {
    add(e) {
      if (!this.newlabel) return
      this.stats.push({
        label: this.newlabel,
        value: 100
      })
      this.newlabel = ''
    },
    remove(stat) {
      if (this.stats.length > 3) {
        this.stats.splice(this.stats.indexOf(stat), 1)
      } else {
        alert('不能在进行删除了')
      }
    }
  }
}
</script>
<style lang="scss" scoped>
label {
    display: inline-block;
    margin-left: 10px;
    width: 20px;
}
.row{
   position: absolute;
    top: 100px;
    left: 300px;
}
</style>
